if lib and not lib.GetTable then


function lib:GetTable(name, key)
	local tb = {}
	local item
	local filter = function() return true end
	
	if type(key) == "function" then
		filter = key
		key = nil
	end
	
	for i = 0, getNumberOf(name) - 1 do
		item = getItem(name, i)
		if filter(item) then
			if key then
				tb[item[key]] = item
			else
				table.insert(tb, item)
			end
		end
	end
	
	return tb
end


function lib:GetSecuritiesTable()
	local tb = {}
	local item, base
	local dt = self:getTradeDate()
	dt = dt.year * 10000 + dt.month * 100 + dt.day
	local count = 0
	local name
	local done
	
	repeat
		done = true
		for i = 0, getNumberOf("securities") - 1 do
			item = getItem("securities", i)
			if lib.global.class_codes[item.class_code]
				and (not item.mat_date or item.mat_date == 0 or item.mat_date > dt)
			then
				name = string.upper(item.code)
				if not tb[name] then
					--message("GetSecuritiesTable code conflict: " .. item.code .. " exists in " .. item.class_code .. " " .. tb[item.code].class_code)
				--else
					if item.base_active_seccode and #item.base_active_seccode > 0
						and item.base_active_classcode and #item.base_active_classcode > 0
					then
						base = tb[string.upper(item.base_active_seccode)]
						if base then
							if not base.base_of__ and lib.global.instrument_base_of then
								base.base_of__ = {}
							end
                            if base.base_of__ then
								table.insert(base.base_of__, name)
								--base.base_of__[name] = item
                            end
                            
							tb[name] = item
							count = count + 1
						else
							done = false
						end
					else
						tb[name] = item
						count = count + 1
					--table.insert(tb, item)
					end
				end
			end
		end
		--message("GetSecuritiesTable " .. tostring(done))
	until(done)
	
	--self:SaveFile(self.path.log .. "securities_table." .. self:GetUser() .. ".txt", self:tostring(tb))
	
	return tb, count
end


end -- of file
